package com.hankol.material.viewmodel

import android.text.InputFilter
import android.text.Spanned
import com.hankol.material.bean.CreateFolderBean
import com.hankol.material.bean.FolderListBean
import java.util.regex.Pattern


/**
 * @author: 关忆北丶
 * @time: 2021/10/25 19:19
 * @description: 创建文件
 */
class MaterialCreateFolderViewModel : MaterialBaseViewModel() {


    /**
     * 禁止输入空格最多可输入10个字
     *
     * @return
     */
    inner class CreateFolderFilter : InputFilter {
        override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int): String? {
            var speChat = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>《》/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]"
            var pattern = Pattern.compile(speChat);
            var matcher = pattern . matcher (source.toString());
            return if (matcher.find()) ""
            else null
        }
    }


    fun dataChanage(bean: CreateFolderBean): FolderListBean {
        val folderBean = FolderListBean()
        folderBean.name = bean.name
        folderBean.ctime = bean.ctime
        folderBean.fileCount = bean.fileCount
        folderBean.id = bean.id
        folderBean.uid = bean.uid
        folderBean.utime = bean.utime
        return folderBean
    }


}